#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int long long
const int inf = 0x3f3f3f3f;
void solve()
{
    int row[9][10] = { 0 };
    int col[9][10] = { 0 };
    int pane[3][3][10] = { 0 };
    vector<vector<int>> a(9, vector<int>(9));
    for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) cin >> a[i][j];
    for (int i = 0; i < 9; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            int x = a[i][j];
            if (x < 1 || x > 9)
            {
                cout << 0 << endl;
                return;
            }
            if (row[i][x] || col[j][x] || pane[i / 3][j / 3][x])
            {
                cout << 0 << endl;
                return;
            }
            row[i][x] = col[j][x] = pane[i / 3][j / 3][x] = 1;
        }
    }
    cout << 1 << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}